﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace HRProject.Code.DTO
{
    public class BLMonthlyWorktime
    {
        private int year;
        private int month;
        private Guid agentId;
        private List<BLDailyWorktime> daysWorktime;
        private string agentFullName;

        public string AgentFullName
        {
            get { return agentFullName; }
            set { agentFullName = value; }
        }

        public List<BLDailyWorktime> DaysWorktime
        {
            get { return daysWorktime; }
            set { daysWorktime = value; }
        }

        public Guid AgentId
        {
            get { return agentId; }
            set { agentId = value; }
        }

        public int Month
        {
            get { return month; }
            set { month = value; }
        }

        public int Year
        {
            get { return year; }
            set { year = value; }
        }

        public float Total
        {
            get
            {
                float result = 0;
                foreach (BLDailyWorktime dw in daysWorktime)
                {
                    result += dw.Total;
                }
                return result;
            }
        }

        public float TotalOver
        {
            get
            {
                float result = 0;
                foreach (BLDailyWorktime dw in daysWorktime)
                {
                    foreach (BLOverWorktime ov in dw.OverWorktimes)
                    {
                        result += ov.Total;
                    }
                }
                return result;
            }
        }

        public BLMonthlyWorktime(Guid agentId, int year, int month)
        {
            this.agentId = agentId;
            this.year = year;
            this.month = month;
            this.daysWorktime = new List<BLDailyWorktime>();
            int daysInMonth = DateTime.DaysInMonth(year, month);
            for (int day = 1; day <= daysInMonth; day++)
            {
                daysWorktime.Add(new BLDailyWorktime(agentId, new DateTime(year, month, day)));
            }
        }
    }
}
